<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>02.JSX</title>
    <script src="https://unpkg.com/react@18/umd/react.development.js"></script>
    <script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
    <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
</head>
<body>
    <h1>02.JSX</h1>
    <div id="app">
       
    </div>
    <!-- 浏览器会忽略不认识的script标签内容 -->
    <script type="text/babel">
        const root = ReactDOM.createRoot(document.querySelector('#app'))

        const username = 'laoxie'

        // JSX
        const vnode = <div className="box">
            <h4 title={username}>Hello {username}</h4>
            <ul>
                {
                    /*
                        //<li>React</li>
                    */
                }
                <li>ReactDOM</li>
            </ul>
            <label htmlFor="username" style={{color:'#f00'}}>用户名：</label>
            <input type="text" id="username" value={username} autoFocus />
        </div>

        // babel会把以上代码变成成下面的代码： JSX -> React.createElement()
        // const vnode2 = React.createElement(
        //     'div',
        //     {className:'box'},
        //     [
        //         React.createElement('h4',null,'Hello'),
        //         React.createElement('ul',null,[
        //             React.createElement('li',null,'React'),
        //             React.createElement('li',null,'ReactDOM'),
        //         ]),
        //     ]
        // );

        // const vn1 = React.createElement('div',null,'123');// 得到一个对象
        // const vn2 = <div>123</div>; // 被babel编译成React.createElement('div',null,'123')
   
        root.render(
            vnode
        )
    </script>
</body>
</html>